# -*- coding: UTF-8 -*-
"""
@author: tgy
@file: 1.5 实现一个优先级队列.py
@time: 2021/01/13
"""
import heapq


class PriorityQueue:

    def __init__(self):
        self._size = 0
        self._nums = []

    def push(self, num, priority):
        ...
        heapq.heappush(self._nums, (-priority, self._size, num))
        self._size += 1

    def pop(self):
        if not len(self._nums):
            raise Exception('priority queue is empty')
        return heapq.heappop(self._nums)[-1]

    def __len__(self):
        return len(self._nums)


if __name__ == '__main__':
    pass
    queue = PriorityQueue()
    queue.push(1, 10)
    queue.push(2, 5)
    queue.push(3, 10)
    queue.push(5, 10)
    queue.push(6, 10)
    while len(queue):
        print(queue.pop())
